var fs = require("fs")

// var cc = require("../../views/front-stage/myperson.html")

const express = require('express')
const { resourceUsage } = require('process')

var paysuccessrouter = express.Router()

var axios = require("axios");
const { userInfo } = require("os");


const jwt = require("jsonwebtoken")


paysuccessrouter.get('/paysuccess', function (req, res) {


    axios({
        url: "video/order/findAllVip",
        method: "post",
    })
        .then(function (data) {
            let allonevip = data.data.object
            res.render("front-stage/paysuccess.html", { userinfo: jwt.decode(req.session.token), allonevip: allonevip })
        })
        .catch(function(error){
            console.log(error)
        })
    
})
/*修改用户vip时间 */
paysuccessrouter.put('/updateUserVipTime', function (req, res) {
    console.log(req.query)
    console.log(978)
    axios({
        url: "video/user/updateUserVipTime",
        method: "put",
        params: {
            orderId: req.query.orderId,
            userId: req.query.userId,
        }
    })
        .then(function (data) {
            console.log(data)
            console.log(29)
            res.status(200).json({
                data: data.data,
            })
        })
        .catch(function (error) {
            res.status(500).json({
                message: '修改vip时间失败'
            })
        })
})

paysuccessrouter.get('/findOrderInnerJoinUser', function (req, res) {
    axios({
        url: "video/payVipOrder/findOrderInnerJoinUser",
        method: "get",
        params: {
            payVipOrderId: req.query.payVipOrderId,
        }
    })
        .then(function (data) {
            res.status(200).json({
                code: 200,
                data: data.data,
                message: '遍历支付订单成功'
            })
        })
        .catch(function (error) {
            res.status(500).json({
                message: '遍历支付订单失败'
            })
        })
})


/*修改vip状态 */
paysuccessrouter.put('/updateUserVip', function (req, res) {
    axios({
        url: "video/user/updateUserVip",
        method: "put",
        params: {
            userId: req.query.userId,
        }
    })
        .then(function (data) {
            res.status(200).json({
                code: 200,
                data: data.data,
                message: '修改vip状态成功'
            })
        })
        .catch(function (error) {
            res.status(500).json({
                message: '修改vip状态失败'
            })
        })
})




/*修改是否已经支付成功 */
paysuccessrouter.get('/updateOfVip', function (req, res) {
    axios({
        url: "video/payVipOrder/updateOfVip",
        method: "get",
        params: {
            payVipOrderId: req.query.payVipOrderId,
        }
    })
        .then(function (data) {
            res.status(200).json({
                code: 200,
                data: data.data,
                message: '修改是否已经支付成功'
            })
        })
        .catch(function (error) {
            res.status(500).json({
                message: '修改是否已经支付失败'
            })
        })
})


/*修改订单支付时间 */
paysuccessrouter.put('/updatePayTime', function (req, res) {
    // let { payVipOrderId}=req.query
    axios({
        url: "video/payVipOrder/updatePayTime",
        method: "put",
        params: {
            payVipOrderId: req.query.payVipOrderId,
        }
    }).then(function (data) {
           
            res.status(200).json({
                data: data.data,
            })
        })
        .catch(function (error) {
           
            res.status(500).json({
                message: error
            })
        })
})
module.exports = paysuccessrouter;